# 写一个映射表：字典
digit_mapping = {
  'A': 10,
  'B': 11,
  'C': 12,
  'D': 13,
  'E': 14,
  'F': 15
}

# Hex - Hexdecimal
# Dec - Decimal
def hex_to_dec(num_str):
  # 字符串是字符的数组
  digits = num_str[2:]
  exp = len(digits)
  decimal = 0

  # 遍历 digits 
  for digit in digits:
    if digit >= 'A' and digit <= 'F':
      decimal += digit_mapping[digit] * pow(16, exp - 1)
    else:
      decimal += int(digit) * pow(16, exp - 1)

    exp -= 1
  
  return decimal

dec_mapping = {
  11 : 'A',
  12 : 'B',
}

def dec_to_hex(num):
  digits = []

  while num != 0:
    reminder = num % 16

    if reminder >= 10 and reminder <= 15:
      digits.append(dec_mapping[reminder])
    else:
      digits.append(reminder)
      
    num //= 16
  
  digits.reverse()
  return "".join(str(digit) for digit in digits)

print(hex_to_dec("0x1A"))

